Sub RenameFiles()
    Dim ws As Worksheet
    Dim folderPath As String
    Dim oldFilename As String
    Dim newFilename As String
    Dim i As Integer
    Dim fileExists As Boolean

    ' 파일명 수정 시트 설정
    Set ws = ThisWorkbook.Sheets("파일명 수정")
    folderPath = "D:\전표처리용\"

    i = 2 ' 헤더가 A1과 B1에 있으므로 데이터는 A2부터 시작

    ' 파일 이름 변경
    Do While ws.Cells(i, 1).Value <> ""
        oldFilename = ws.Cells(i, 1).Value
        newFilename = ws.Cells(i, 2).Value
        fileExists = Len(Dir(folderPath & oldFilename)) > 0
        
        If fileExists Then
            Name folderPath & oldFilename As folderPath & newFilename
        Else
            MsgBox "파일 " & oldFilename & "을(를) 찾을 수 없습니다.", vbExclamation
        End If
        
        i = i + 1
    Loop

    MsgBox "파일 이름 변경 작업이 완료되었습니다.", vbInformation
End Sub